from api import client
# from common.read_yaml import ReadYamlConfigs
from common.route import *
from until.phone import TestFaker
from common.read_yaml import get_yaml_filepath
from common.readconfig import Environ

# from common.logintoken import login1
data = get_yaml_filepath(Environ=Environ)


from api.client import HttpClient
clent1 = HttpClient()
data0 = login['case_data'][0]['body']
def login1(username=data0['username']
          , password=data0['password']):
    etc = {
        "username": username
        , "password": password
    }

    url = login['url']
    method = login['method']
    url = clent1.get_full_url(url, etc=etc)
    return clent1.send(url, method=method)

class MemberControllerApi(client.HttpClient):
    def __init__(self,token):
        self.host = data['admin_host']
        self.token = token

    """-----------------------------------商城前台---------------------------------"""
    """获取注册验证码"""
    data0 = get_auth_code['case_data'][0]['body']
    def get_auth_code(self,telephone = TestFaker().get_phone_number()):
        etc = {
            "telephone":telephone
        }
        url = get_auth_code['url']
        method = get_auth_code['method']
        url = self.get_full_url(url,etc=etc)
        return self.send(url,method=method)

    """注册"""
    data0 = register['case_data'][0]['body']
    def register(self
                 ,authCode=data0['authCode']
                 ,password=data0['password']
                 ,telephone=data0['telephone']
                 ,username=data0['username']):
        etc = {
            "authCode": authCode,
            "password": password,
            "telephone": telephone,
            "username": username
        }
        url = register['url']
        method = register['method']
        url = self.get_full_url(url,etc)
        return self.send(url,method=method)



    """登录接口封装"""
    data0 = login['case_data'][0]['body']
    def login(self,username=data0['username']
          , password=data0['password']):
        return login1(username=username
          , password=password)
